package faf.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import faf.business.ReportManager;
import faf.business.SurveyManager;
import faf.entities.Account;
import faf.entities.Survey;

public class FullReportController  implements Controller {
	SurveyManager surveyManager;
	ReportManager reportManager;
	
	public ReportManager getReportManager() {
		return reportManager;
	}

	public void setReportManager(ReportManager reportManager) {
		this.reportManager = reportManager;
	}

	public SurveyManager getSurveyManager() {
		return surveyManager;
	}

	public void setSurveyManager(SurveyManager manager) {
		this.surveyManager = manager;
	}	

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		long id = Long.parseLong(request.getParameter("id"));

		Survey survey = surveyManager.get(id);
		Account user = (Account) request.getSession().getAttribute("user");

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("survey", survey);
		
		if (reportManager.canSeeFullreport(user, survey)==true){
			List<?> report = reportManager.getFullReport(survey.getId());
			map.put("report", report);
			return new ModelAndView("full_report", map);
		}
		
		return new ModelAndView("report_access_denied");
	}

	
	
}
